package com.gxa.controller.zhy;

import com.gxa.common.R;
import com.gxa.pojo.Params;
import com.gxa.pojo.Params_Son;
import com.gxa.pojo.zhy.Paging;
import com.gxa.service.ConfigurationVariablesService;
import io.swagger.annotations.*;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 赵贺益
 * Date: 2021/12/04 10:32
 * Description:
 * Version: V1.0
 */
@Controller
@Api(value ="" ,tags = "系统管理模块接口（配置变量）2 ")
@RequestMapping("/system")
public class ConfigurationVariablesController {
    @Autowired
    private ConfigurationVariablesService configurationVariablesService;
    /**
     * 查询所有的配置变量相关信息的接口，用于显示到表中
     * @return
     */

    @ResponseBody
    @RequestMapping(value ="/queryAllConfig",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有的配置变量相关信息的接口",notes = "返回的是一个R对象，R对象中的data中装了一个对象List<Params>(集合对象)用于显示到表中，对象结构如下",httpMethod = "GET", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "查询成功"),
            @ApiResponse(code=504,message = "数据库中无变量值"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })

    public R  queryAllConfigParams(Integer currentPage,Integer pageSize){
        R r=configurationVariablesService.queryAllConfigParams(currentPage,pageSize);
        return r;

    }

    /**
     * 根据关键字模糊查询
     */
    @ResponseBody
//    @RequestMapping(value ="/queryAllConfigByMessage",method = RequestMethod.POST)
    @RequestMapping(value ="/queryAllConfigByMessage",method = RequestMethod.GET)
    @ApiOperation(value = "根据关键字模糊查询所有的配置变量相关信息的接口",notes = "返回的是一个R对象，R对象中的data中装了一个对象List<Params>(集合对象)用于显示到表中，对象结构如下",httpMethod = "GET", response = R.class)
//    @ApiImplicitParam(name = "message",value = "模糊输入的值",required =true,paramType ="query")

    @ApiResponses({
            @ApiResponse(code=200,message = "查询成功"),
            @ApiResponse(code=504,message = "数据库中无变量值"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })

//    public  R queryAllConfigByMessage(@RequestBody @ApiParam Paging paging){
    public  R queryAllConfigByMessage(Integer currentPage,Integer pageSize,String message){

//        R r=configurationVariablesService.queryAllConfigByMessage(paging);
        R r=configurationVariablesService.queryAllConfigByMessage(currentPage,pageSize,message);
        return r;
    }


    /**
     * 查询配置变量值的接口（用于下拉框显示）
     * @param
     * @return
     */


    @ResponseBody
    @RequestMapping(value ="/queryParam_value",method = RequestMethod.POST)
    @ApiOperation(value = "查询配置变量值的接口",notes = "返回的是一个R对象，R对象中的data中装了一个List(集合对象)（用于下拉框显示），对象结构如下",httpMethod = "POST", response =R.class)
    @ApiImplicitParam(name = "param_id",value = "选中行配置变量的ID",required =true,paramType ="query")
//    public  List<Params_Son> queryParam_value(Integer param_id){
    @ApiResponses({
            @ApiResponse(code=200,message = "查询成功"),
            @ApiResponse(code=504,message = "查询失败"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R queryParam_value(@RequestBody Params params ){
        Integer param_id=params.getParam_id();
        R r=configurationVariablesService.queryParam_value(param_id);
        System.out.println(r);
        return r;
    }

    /**
     * 添加配置变量值的接口
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping(value ="/addParam_value",method = RequestMethod.POST)
    @ApiOperation(value = "添加配置变量值的接口",notes = "返回的是一个R对象,结构如下",httpMethod = "POST", response =R.class)
    @ApiImplicitParams({
              @ApiImplicitParam(name = "param_value",value = "输入框中新增的配置变量的值",required =true,paramType ="query"),
              @ApiImplicitParam(name = "param_id",value = "当前新增变量值对应的变量id（即选中行的id）",required =true,paramType ="query")
      })
    @ApiResponses({
            @ApiResponse(code=200,message = "添加成功"),
            @ApiResponse(code=500,message = "该变量值已经存在"),
//            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R addParam_value(@RequestBody Params_Son params_son){
        String param_value=params_son.getParam_value();
        Integer  param_id=params_son.getParam_id();
        R r=configurationVariablesService.addParam_value(param_id,param_value);
        return  r;

    }

    /**
     * 下拉框中选中的配置变量值根据值的id进行删除
     * @param
     * @return
     */

    @ResponseBody
    @RequestMapping(value ="/deleteParam_valueByParam_son_id",method = RequestMethod.POST)
    @ApiOperation(value = "删除配置变量值的接口",notes = "返回的是一个R对象,结构如下",httpMethod = "POST", response =R.class)
    @ApiImplicitParam(name = "param_son_id",value = "下拉框中选中的配置变量的值的id（param_son_id）",required =true,paramType ="query")
    @ApiResponses({
            @ApiResponse(code=200,message = "删除成功"),
            @ApiResponse(code = 500,message = "后台服务错误")

    })
    public  R deleteParam_valueByParam_son_id(@RequestBody Params_Son params_son){
        Integer param_son_id=params_son.getParam_son_id();
        R r=configurationVariablesService.deleteParam_valueByParam_son_id(param_son_id);
        return r;
    }

}
